package com.wxzz.elearing.user.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.EnterpriseDto;
import com.wxzz.elearing.user.entity.Enterprise;
import com.wxzz.elearing.user.service.IEnterpriseService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/wx-enterprise")
@Api(tags = "企业接口(小程序)")
public class WxEnterpriseController {

    @Autowired
    private IEnterpriseService enterpriseService;

    @ApiOperation(value = " 企业列表(小程序)", notes = " 企业列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listEnterprise", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Enterprise>>> listEnterprise(HttpServletResponse response, @RequestBody EnterpriseDto enterpriseDto) {
        return enterpriseService.listEnterprise(response, enterpriseDto);
    }

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = " 查看你的企业是否禁用(小程序)", notes = " 查看你的企业是否禁用(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "isBanEnterprise", method = RequestMethod.POST)
    public ReturnVO isBanEnterprise(@RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseService.isBanEnterprise(jsonObject.getLong("enterpriseId"));
    }

}
